package licode.unisop.authcenter.application.executor;

import licode.unisop.authcenter.application.info.RealmLookupIn;
import licode.unisop.authcenter.application.info.RealmQueryPageIn;
import licode.unisop.provider.vo.SiPageResult;
import licode.unisop.realm.client.api.SiRealmQueryService;
import licode.unisop.realm.client.dto.SiRealmDTO;
import licode.unisop.realm.client.info.SiRealmQueryPageIn;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 定义统一认证平台中心领域查询相关接口
 *
 * @author licode
 */
@Service
public class CenterRealmQueryExecutor {
    @Resource
    private SiRealmQueryService siRealmQueryService;

    /**
     * 分页查询领域信息
     */
    public SiPageResult<SiRealmDTO> queryPage(RealmQueryPageIn req) {
        return siRealmQueryService.queryRealmPage(SiRealmQueryPageIn
                .builder().current(req.getCurrent())
                .pageSize(req.getPageSize() == null ? 20 : req.getPageSize())
                .name(req.getRealmName())
                .startTime(req.getStartTime())
                .endTime(req.getEndTime())
                .build());
    }

    /**
     * 查询指定领域信息
     */
    public SiRealmDTO lookup(RealmLookupIn req) {
        return siRealmQueryService.findRealm(req.getId());
    }
}
